package com.zjb.demo.system.controller;

import com.mybatisflex.core.paginate.Page;
import com.zjb.demo.common.domain.response.AjaxResult;
import com.zjb.demo.system.domain.SysNotice;
import com.zjb.demo.system.domain.query.SysNoticeQuery;
import com.zjb.demo.system.service.SysNoticeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.noear.solon.annotation.*;

import java.util.List;

/**
 * @author 庄佳彬
 * @since 2023/12/30 22:11
 */
@Controller
@Mapping("/system/notice")
@Api(tags = "系统：通知公告管理")
public class SysNoticeController {
    @Inject
    private SysNoticeService noticeService;

    @Get
    @Mapping("/list")
    @ApiOperation(value = "通知公告列表")
    public AjaxResult<Page<SysNotice>> list(SysNoticeQuery query) {
        return AjaxResult.success(noticeService.pageList(query));
    }

    @Get
    @Mapping("/{noticeId}")
    @ApiOperation(value = "通知公告详情")
    public AjaxResult<SysNotice> detail(Long noticeId) {
        return AjaxResult.success(noticeService.getById(noticeId));
    }

    @Post
    @Mapping
    @ApiOperation(value = "通知公告新增")
    public AjaxResult<Boolean> save(@Body SysNotice notice) {
        return AjaxResult.success(noticeService.save(notice));
    }

    @Put
    @Mapping
    @ApiOperation(value = "通知公告修改")
    public AjaxResult<Boolean> update(@Body SysNotice notice) {
        return AjaxResult.success(noticeService.updateById(notice));
    }

    @Delete
    @Mapping("/{noticeIds}")
    @ApiOperation(value = "通知公告删除")
    public AjaxResult<Boolean> delete(Long[] noticeIds) {
        return AjaxResult.success(noticeService.removeByIds(List.of(noticeIds)));
    }
}
